import { createStore } from 'vuex'
import router from '../router'

export default createStore({
    state: {
        constant: {
            base_url: 'https://images.weserv.nl/?url=',
        },
        loginView: false,
        isLogin: false,
        userInfo: {}
    },
    getters: {},
    mutations: {
        changeLogin(state) {
            if (!sessionStorage.getItem('token')) {
                state.isLogin = false
                state.userInfo = {}
            } else {
                state.isLogin = true
            }
        },
        getUser(state) {
            state.userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
        },
        changeLoginView(state, istrue) {
            state.loginView = istrue
        },
        goDetail(state, id) {
            const url = '/detail/' + id
            const routeData = router.resolve({ path: url })
            window.open(routeData.href, '_blank')
        },
        goUser(state, id) {
            const url = '/user/' + id
            const routeData = router.resolve({ path: url })
            window.open(routeData.href, '_blank')
        }
    },
    actions: {},
    modules: {}
})